package com.fita.admin.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.principal.District;
import com.fita.entity.principal.Principal;

import java.util.List;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface PrincipalDao {
    
    /**
     * 
     * @param authority
     * @param district
     * @return
     */
    @Query("SELECT COUNT(*) FROM Principal WHERE authority = :authority AND district = :district")
    public int count(@Variable("authority") String authority, @Variable("district") District district);

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM Principal")
    public int count();
    
    /**
     * @param authority
     * @param district
     * @return
     */
    @Query("FROM Principal WHERE authority = :authority AND district = :district AND disabled = false")
    public List<Principal> list(@Variable("authority") String authority, @Variable("district") District district);
    
    /**
     * 
     * @param authority
     * @param district
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Principal WHERE authority = :authority AND district = :district AND disabled = false")
    public List<Principal> list(@Variable("authority") String authority, @Variable("district") District district, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * @param authority
     * @return
     */
    @Query("FROM Principal WHERE authority = :authority AND disabled = false")
    public List<Principal> listSaleUser(@Variable("authority") String authority);

    /**
     * 
     * @param username
     * @return
     */
    @Query("FROM Principal WHERE disabled = false AND username = :username")
    public Principal load(@Variable("username") String username);

    @Limit
    @Query("FROM Principal")
    public List<Principal> listByPage(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    /**
     * @param authorities
     * @param district
     * @return
     */
    @Query("FROM Principal WHERE authority IN (:authorities) AND district = :district AND disabled = false")
    public List<Principal> list(@Variable("authorities") List<String> authorities, @Variable("district") District district);
    
    /**
     * @param district
     * @return
     */
    @Query("FROM Principal WHERE district = :district AND disabled = false")
    public List<Principal> list(@Variable("district") District district);
    
}
